/**
 * 作者: hxl
 * 日期: 2025-05-16 17:21:38
 * 备注: 联盟乱斗公告
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUnionScuffleNotice;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UnionScuffleNoticeModel extends BaseModel implements Model {
    public static final String LISTKEY = "act_id";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // id
    protected long unionId; // 被挑战联盟id
    protected String unionName = ""; // 被挑战联盟名字
    protected String attackerName = ""; // 挑战者名字
    protected long attackUnionId; // 挑战者联盟id
    protected String attackUnionName = ""; // 挑战者联盟名字
    protected int totalMemberCount; // 被挑战者总人数
    protected int defeatMemberCount; // 总击败人数
    protected String attackerIcon = ""; // 挑战者头像
    protected long addTime; // 公告产生时间
    protected long actId; // 活动id

    public void reset() {
    }

    protected String getKey() {
        return "UnionScuffleNotice." + id;
    }

    protected String getListKey() {
        return "UnionScuffleNotice." + actId;
    }

    protected String getListItemKey() {
        return id + "";
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("union_scuffle_notice"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, 0, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // id
        obj.put("unionId", unionId); // 被挑战联盟id
        obj.put("unionName", unionName); // 被挑战联盟名字
        obj.put("attackerName", attackerName); // 挑战者名字
        obj.put("attackUnionId", attackUnionId); // 挑战者联盟id
        obj.put("attackUnionName", attackUnionName); // 挑战者联盟名字
        obj.put("totalMemberCount", totalMemberCount); // 被挑战者总人数
        obj.put("defeatMemberCount", defeatMemberCount); // 总击败人数
        obj.put("attackerIcon", attackerIcon); // 挑战者头像
        obj.put("addTime", addTime); // 公告产生时间
        obj.put("actId", actId); // 活动id
        return obj;
    }

    public PBUnionScuffleNotice.Builder takeInitBuilder() {
        PBUnionScuffleNotice.Builder sb = PBUnionScuffleNotice.newBuilder();
        if (id != 0) {
            sb.setId(id);
        }
        if (unionId != 0) {
            sb.setUnionId(unionId);
        }
        if (!unionName.isEmpty()) {
            sb.setUnionName(unionName);
        }
        if (!attackerName.isEmpty()) {
            sb.setAttackerName(attackerName);
        }
        if (attackUnionId != 0) {
            sb.setAttackUnionId(attackUnionId);
        }
        if (!attackUnionName.isEmpty()) {
            sb.setAttackUnionName(attackUnionName);
        }
        if (totalMemberCount != 0) {
            sb.setTotalMemberCount(totalMemberCount);
        }
        if (defeatMemberCount != 0) {
            sb.setDefeatMemberCount(defeatMemberCount);
        }
        if (!attackerIcon.isEmpty()) {
            sb.setAttackerIcon(attackerIcon);
        }
        if (addTime != 0) {
            sb.setAddTime(addTime);
        }
        return sb;
    }

    public PBUnionScuffleNotice.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUnionScuffleNotice.Builder sb = PBUnionScuffleNotice.newBuilder();
        if (isFieldUpdate("id")) {
            sb.setId(id);
        }
        if (isFieldUpdate("unionId")) {
            sb.setUnionId(unionId);
        }
        if (isFieldUpdate("unionName")) {
            sb.setUnionName(unionName);
        }
        if (isFieldUpdate("attackerName")) {
            sb.setAttackerName(attackerName);
        }
        if (isFieldUpdate("attackUnionId")) {
            sb.setAttackUnionId(attackUnionId);
        }
        if (isFieldUpdate("attackUnionName")) {
            sb.setAttackUnionName(attackUnionName);
        }
        if (isFieldUpdate("totalMemberCount")) {
            sb.setTotalMemberCount(totalMemberCount);
        }
        if (isFieldUpdate("defeatMemberCount")) {
            sb.setDefeatMemberCount(defeatMemberCount);
        }
        if (isFieldUpdate("attackerIcon")) {
            sb.setAttackerIcon(attackerIcon);
        }
        if (isFieldUpdate("addTime")) {
            sb.setAddTime(addTime);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public long getUnionId() {
        return unionId;
    }

    public void putUnionId(long unionId) {
        if (this.unionId != unionId) {
            this.unionId = unionId;
            updateRedisHashField(getKey(), "unionId", this.unionId);
        }
    }

    public void addUnionId(long value) {
        this.unionId += value;
        updateRedisHashField(getKey(), "unionId", this.unionId);
    }

    public String getUnionName() {
        return unionName;
    }

    public void putUnionName(String unionName) {
        if (!this.unionName.equals(unionName)) {
            this.unionName = unionName;
            updateRedisHashField(getKey(), "unionName", this.unionName);
        }
    }

    public String getAttackerName() {
        return attackerName;
    }

    public void putAttackerName(String attackerName) {
        if (!this.attackerName.equals(attackerName)) {
            this.attackerName = attackerName;
            updateRedisHashField(getKey(), "attackerName", this.attackerName);
        }
    }

    public long getAttackUnionId() {
        return attackUnionId;
    }

    public void putAttackUnionId(long attackUnionId) {
        if (this.attackUnionId != attackUnionId) {
            this.attackUnionId = attackUnionId;
            updateRedisHashField(getKey(), "attackUnionId", this.attackUnionId);
        }
    }

    public void addAttackUnionId(long value) {
        this.attackUnionId += value;
        updateRedisHashField(getKey(), "attackUnionId", this.attackUnionId);
    }

    public String getAttackUnionName() {
        return attackUnionName;
    }

    public void putAttackUnionName(String attackUnionName) {
        if (!this.attackUnionName.equals(attackUnionName)) {
            this.attackUnionName = attackUnionName;
            updateRedisHashField(getKey(), "attackUnionName", this.attackUnionName);
        }
    }

    public int getTotalMemberCount() {
        return totalMemberCount;
    }

    public void putTotalMemberCount(int totalMemberCount) {
        if (this.totalMemberCount != totalMemberCount) {
            this.totalMemberCount = totalMemberCount;
            updateRedisHashField(getKey(), "totalMemberCount", this.totalMemberCount);
        }
    }

    public void addTotalMemberCount(int value) {
        this.totalMemberCount += value;
        updateRedisHashField(getKey(), "totalMemberCount", this.totalMemberCount);
    }

    public int getDefeatMemberCount() {
        return defeatMemberCount;
    }

    public void putDefeatMemberCount(int defeatMemberCount) {
        if (this.defeatMemberCount != defeatMemberCount) {
            this.defeatMemberCount = defeatMemberCount;
            updateRedisHashField(getKey(), "defeatMemberCount", this.defeatMemberCount);
        }
    }

    public void addDefeatMemberCount(int value) {
        this.defeatMemberCount += value;
        updateRedisHashField(getKey(), "defeatMemberCount", this.defeatMemberCount);
    }

    public String getAttackerIcon() {
        return attackerIcon;
    }

    public void putAttackerIcon(String attackerIcon) {
        if (!this.attackerIcon.equals(attackerIcon)) {
            this.attackerIcon = attackerIcon;
            updateRedisHashField(getKey(), "attackerIcon", this.attackerIcon);
        }
    }

    public long getAddTime() {
        return addTime;
    }

    public void putAddTime(long addTime) {
        if (this.addTime != addTime) {
            this.addTime = addTime;
            updateRedisHashField(getKey(), "addTime", this.addTime);
        }
    }

    public void addAddTime(long value) {
        this.addTime += value;
        updateRedisHashField(getKey(), "addTime", this.addTime);
    }

    public long getActId() {
        return actId;
    }

    public void putActId(long actId) {
        if (this.actId != actId) {
            this.actId = actId;
            updateRedisHashField(getKey(), "actId", this.actId);
        }
    }

    public void addActId(long value) {
        this.actId += value;
        updateRedisHashField(getKey(), "actId", this.actId);
    }

}